layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格id
    };

    Notice.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id'},
            {field: 'pid', align: "center", hide: true, sort: true, title: 'pid'},
            {field: 'ssctbh', align: "center", sort: true, title: '所属餐厅编号', width: 130},
            {field: 'ssctdm', align: "center", sort: true, title: '所属餐厅店名', width: 130},
            {field: 'zw', align: "center", sort: true, title: '职位', width: 130},
            {field: 'fzr', align: "center", sort: true, title: '负责人'},
            {field: 'lxfs', align: "center", sort: true, title: '联系方式', width: 130},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 130}
        ]];
    };

    /**
     * 点击删除通知
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onDeleteNotice = function (data) {
        var pid = data.pid;
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/btyTxl/view_delete", function (data) {
                Feng.success("删除成功!");
                table.reload(Notice.tableId);
            });
            ajax.set("pid", pid);
            ajax.start();
        };
        Feng.confirm("是否删除 ?", operation);
        return false;
    };
    /**
     * 点击修改
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onEditNotice = function (data) {
        func.open({
            height: 980,
            title: '修改负责人信息',
            content: Feng.ctxPath + "/btyTxl/view_update_getByID/" + data.pid,
            tableId: Notice.tableId
        });

    };
    // 渲染表格
    var tableResult = table.render({
        elem: "#" + Notice.tableId,
        url: Feng.ctxPath + '/btyTxl/view',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        limit: 20,
        cols: Notice.initColumn()
    });

    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'delete') {
            Notice.onDeleteNotice(data);
        }
    });
});